﻿using System;
using System.Collections.Generic;
using System.Text;
using FreeSql;
using FreeSql.DataAnnotations;

namespace ED.FreeSql.Core
{
    #region 基础实体

    /// <summary>
    /// 基础实体接口
    /// </summary>
    public interface IBaseEntity
    {
    }
    /// <summary>
    /// 基础实体,主键名为Id,主键类型开放
    /// </summary>
    /// <typeparam name="TPrimaryKey"></typeparam>
    public abstract class BaseEntity<TPrimaryKey> : IBaseEntity
    {
        [Column(IsPrimary = true, IsIdentity = true)]
        public virtual TPrimaryKey Id { get; set; }
    }

    /// <summary>
    /// 基础实体,主键为int类型的Id列
    /// </summary>
    public abstract class BaseEntity : BaseEntity<int> { }

    /// <summary>
    /// 基础实体,主键为Guid类型的Id列
    /// </summary>
    public abstract class BaseGuidEntity : BaseEntity<Guid> { }
    #endregion

    #region 审计功能接口
    /// <summary>
    /// 删除动作的审计接口
    /// </summary>
    public interface IAuditDeleted
    {
        /// <summary>
        /// 是否删除
        /// </summary>
        bool IsDeleted { set; get; }
    }

    /// <summary>
    /// 更新动作的审计接口
    /// </summary>
    public interface IAuditUpdated
    {
        /// <summary>
        /// 更新日期
        /// </summary>
        DateTime? UpdatedDate { get; set; }
        /// <summary>
        /// 更新的操作人
        /// </summary>
        int? UpdatedBy { get; set; }
    }

    /// <summary>
    /// 新增动作的审计接口
    /// </summary>
    public interface IAuditCreated
    {
        /// <summary>
        /// 创建日期
        /// </summary>
        DateTime CreatedDate { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        int? CreatedBy { get; set; }
    }

    #endregion

    #region 含全部审计功能的实体
    /// <summary>
    /// 全审计接口(含新增、更新和删除动作)
    /// </summary>
    public interface IAuditEntity : IBaseEntity, IAuditCreated, IAuditUpdated, IAuditDeleted
    {
    }

    /// <summary>
    /// 包含审计跟踪的基类,主键名为Id,主键类型开放
    /// </summary>
    /// <typeparam name="TPrimaryKey"></typeparam>
    public abstract class AuditEntity<TPrimaryKey> : BaseEntity<TPrimaryKey>, IAuditEntity
    {
        /// <summary>
        /// 创建日期
        /// </summary>
        public virtual DateTime CreatedDate { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public virtual int? CreatedBy { get; set; }
        /// <summary>
        /// 是否删除
        /// </summary>
        public virtual bool IsDeleted { get; set; }
        /// <summary>
        /// 更新日期
        /// </summary>
        public virtual DateTime? UpdatedDate { get; set; }
        /// <summary>
        /// 更新的操作人
        /// </summary>
        public virtual int? UpdatedBy { get; set; }

    }
    /// <summary>
    ///  包含追踪基类,主键为int类型的Id列
    /// </summary>
    public abstract class AuditEntity : AuditEntity<int> { }

    /// <summary>
    /// 包含追踪基类,主键为Guid类型的Id列
    /// </summary>
    public abstract class AuditGuidEntity : AuditEntity<Guid> { }
    #endregion
}
